home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / AI88PATT / PATTERN.C < prev   
C/C++ Source or Header  |  1990-01-08  |  7KB  |  247 lines

  1. /* program to generate Adobe Illustrator Patterns from 
  2. hexadecimally encoded MacDraw/MacPaint Type
  3. Patterns. Written by Jeff Meredith 12/89. Internet Address meredith@erl.mit.edu
  4.  
  5. Strategy
  6. Use Illustrator commands to stroke lines one point in width across a row. If black bits are contiguous then test and draw line contiguously.
  7.  
  8. Instructions. Double click on Application or run from within
  9. the Think C 4.0 environment. Input name for file at standard file
  10. dialog box, then answer questions by typing, if the default (in brackets[]) is ok then 
  11. just hit return. Transparent patterns will have their whited areas be transparent.
  12. Input the two digit hexadecimal encoding for each row individually
  13.  
  14. A header for a typical pattern follows and will be output by the program:
  15.     %%BeginPattern: (Acid_Igneous) a sample pattern
  16.     (Acid_Igneous) 150.5 198.5 162.5 206.5 [
  17.     (0 O 0 R 1 g 1 G) @
  18.     _ &
  19.     (0 O 0 R 0 g 0 G) @
  20.     (
  21.     0 i 0 J 0 j 0.25 w 4 M []0 d
  22.     %%Note:
  23.     150.5 203.5 m
  24.     152.5 203.5 l*/
  25.  
  26. #include<stdio.h>
  27. #include<string.h>
  28. #include<stdlib.h>
  29. #include<console.h>
  30. #define HEX "FF" /* default text value */
  31. #define PATTERN "Test Pattern" 
  32. #define QUIT "y" 
  33. #define TRANSPARENT "n"
  34. #define column1 150
  35. #define column2 151
  36. #define column3 152
  37. #define column4 153
  38. #define column5 154
  39. #define column6 155
  40. #define column7 156
  41. #define column8 157
  42. #define column9 158
  43.  
  44. FILE *fopen(),*PPtr;
  45. main()
  46. {
  47. char putfile1[255];
  48. char hexvalue[2],pattern_name[40],buffer[128],answer[2],transparent[2];
  49. int row[8];
  50. void getstrng(),header(),trailer();
  51. printf("Program to take encoded MacDraw Patterns and convert them into Illustrator Patterns\n");
  52.  
  53. /* use StdPutFile Dialog Box to specify filename */
  54. if(putfile(putfile1,"Name of output pattern file:","Illus.Patterns") != 0);
  55.     PPtr=fopen(putfile1,"w");
  56. header();
  57. strcpy(answer,"n");
  58. while(strcmp(answer,"y")){
  59.     getstrng("Name of Pattern",PATTERN,pattern_name,buffer);
  60.       fprintf(PPtr,"%%%%BeginPattern: (%s)\n",pattern_name);
  61.       fprintf(PPtr,"(%s) 150 206.5 158 198.5 [\n",pattern_name);
  62.         
  63.     getstrng("transparent",TRANSPARENT,transparent,buffer);
  64.     if(!strcmp(transparent,"y"))
  65.        fprintf(PPtr,"%%%%Tile\n");
  66.     else
  67.     { fprintf(PPtr,"(0 O 0 R 1 g 1 G)@\n");
  68.       fprintf(PPtr,"_ &\n");
  69.     }
  70.     fprintf(PPtr,"(0 O 0 R 0 g 0 G)@\n");
  71.     fprintf(PPtr,"(\n");
  72.     fprintf(PPtr,"0 i 0 J 0 j 1 w 4 M []0 d\n");
  73.     fprintf(PPtr,"%%%%Note:\n");
  74.  
  75.     
  76.     getstrng("hexvalue",HEX,hexvalue,buffer);
  77.     row[0]=206;
  78.     decompose(row[0],hexvalue);
  79.  
  80.     getstrng("hexvalue",HEX,hexvalue,buffer);
  81.     row[1]=205;
  82.     decompose(row[1],hexvalue);
  83.  
  84.     getstrng("hexvalue",HEX,hexvalue,buffer);
  85.     row[2]=204;
  86.     decompose(row[2],hexvalue);
  87.  
  88.     getstrng("hexvalue",HEX,hexvalue,buffer);
  89.     row[3]=203;
  90.     decompose(row[3],hexvalue);
  91.  
  92.     getstrng("hexvalue",HEX,hexvalue,buffer);
  93.     row[4]=202;
  94.     decompose(row[4],hexvalue);
  95.  
  96.     getstrng("hexvalue",HEX,hexvalue,buffer);
  97.     row[5]=201;
  98.     decompose(row[5],hexvalue);
  99.  
  100.     getstrng("hexvalue",HEX,hexvalue,buffer);
  101.     row[6]=200;
  102.     decompose(row[6],hexvalue);
  103.  
  104.     getstrng("hexvalue",HEX,hexvalue,buffer);
  105.     row[7]=199;
  106.     decompose(row[7],hexvalue);
  107.     
  108.     fprintf(PPtr,") &\n] E\n%%%%EndPattern\n");
  109.  
  110.     getstrng("Quit,y/n",QUIT,answer,buffer);
  111.     if(!strcmp(answer,"y")){
  112.         trailer();
  113.         ExitToShell();
  114.      }
  115. }
  116. }
  117. decompose(rownumber,hexvalue)
  118. int rownumber;
  119. char hexvalue[];
  120. {
  121. int value1=0,value2=0;
  122. int moveflag,lineflag;
  123. if(!strncmp(&hexvalue[0],"F",1))value1=15;
  124. if(!strncmp(&hexvalue[0],"E",1))value1=14;
  125. if(!strncmp(&hexvalue[0],"D",1))value1=13;
  126. if(!strncmp(&hexvalue[0],"C",1))value1=12;
  127. if(!strncmp(&hexvalue[0],"B",1))value1=11;
  128. if(!strncmp(&hexvalue[0],"A",1))value1=10;
  129. if(!strncmp(&hexvalue[0],"9",1))value1=9;
  130. if(!strncmp(&hexvalue[0],"8",1))value1=8;
  131. if(!strncmp(&hexvalue[0],"7",1))value1=7;
  132. if(!strncmp(&hexvalue[0],"6",1))value1=6;
  133. if(!strncmp(&hexvalue[0],"5",1))value1=5;
  134. if(!strncmp(&hexvalue[0],"4",1))value1=4;
  135. if(!strncmp(&hexvalue[0],"3",1))value1=3;
  136. if(!strncmp(&hexvalue[0],"2",1))value1=2;
  137. if(!strncmp(&hexvalue[0],"1",1))value1=1;
  138. if(!strncmp(&hexvalue[0],"0",1))value1=0;
  139.  
  140. if(!strcmp(&hexvalue[1],"F"))value2=15;
  141. if(!strcmp(&hexvalue[1],"E"))value2=14;
  142. if(!strcmp(&hexvalue[1],"D"))value2=13;
  143. if(!strcmp(&hexvalue[1],"C"))value2=12;
  144. if(!strcmp(&hexvalue[1],"B"))value2=11;
  145. if(!strcmp(&hexvalue[1],"A"))value2=10;
  146. if(!strcmp(&hexvalue[1],"9"))value2=9;
  147. if(!strcmp(&hexvalue[1],"8"))value2=8;
  148. if(!strcmp(&hexvalue[1],"7"))value2=7;
  149. if(!strcmp(&hexvalue[1],"6"))value2=6;
  150. if(!strcmp(&hexvalue[1],"5"))value2=5;
  151. if(!strcmp(&hexvalue[1],"4"))value2=4;
  152. if(!strcmp(&hexvalue[1],"3"))value2=3;
  153. if(!strcmp(&hexvalue[1],"2"))value2=2;
  154. if(!strcmp(&hexvalue[1],"1"))value2=1;
  155. if(!strcmp(&hexvalue[1],"0"))value2=0;
  156. moveflag=0; /* draw points with continuous lines if possible */
  157. if(value1>=8){
  158.     fprintf(PPtr,"%d %d m\n",column1,rownumber);
  159.         moveflag=1;
  160.         value1-=8;
  161. }
  162. if(value1<4&&moveflag==1){
  163.     fprintf(PPtr,"%d %d l\nS\n",column2,rownumber);
  164.         moveflag=0;
  165. } /* if value 1<4 draw point if needed fall through */
  166. if(value1>=4){
  167.     if(moveflag==0){
  168.            fprintf(PPtr,"%d %d m\n",column2,rownumber); 
  169.            moveflag=1;
  170.    }
  171.            value1-=4; /* continue drawing line */
  172. }    /*   value1<4 and move flag set type fprintf(%d %d l)*/
  173. if(value1<2&&moveflag==1){
  174.     fprintf(PPtr,"%d %d l\nS\n",column3,rownumber);
  175.     moveflag=0;
  176. }
  177. if(value1>=2){
  178.     if(moveflag==0){
  179.         fprintf(PPtr,"%d %d m\n",column3,rownumber); 
  180.                 moveflag=1;
  181.     }
  182.             value1-=2;
  183. }
  184. if(value1<1&&moveflag==1){    
  185.     fprintf(PPtr,"%d %d l\nS\n",column4,rownumber);
  186.     moveflag=0;
  187.     }
  188. if(value1==1){
  189.     if(moveflag==0){
  190.         fprintf(PPtr,"%d %d m\n",column4,rownumber); 
  191.                 moveflag=1;
  192.         if(value2<8){ 
  193.             fprintf(PPtr,"%d %d l\nS\n",column5,rownumber);
  194.         moveflag=0;
  195.     }
  196.     }
  197. else{     /* move flag =1 */
  198. if(value2<8){
  199.     fprintf(PPtr,"%d %d l\nS\n",column5,rownumber);
  200.     moveflag=0;
  201. }
  202. }
  203. }
  204.  
  205. if(value2>=8){
  206.     if(moveflag==0){
  207.               fprintf(PPtr,"%d %d m\n",column5,rownumber);
  208.           moveflag=1;
  209.       }
  210.         value2-=8;
  211. }
  212. if(value2<4&&moveflag==1){
  213.     fprintf(PPtr,"%d %d l\nS\n",column6,rownumber);
  214.         moveflag=0;
  215. } /* if value 1<4 draw point if needed fall through */
  216. if(value2>=4){
  217.     if(moveflag==0){
  218.            fprintf(PPtr,"%d %d m\n",column6,rownumber); 
  219.            moveflag=1;
  220.    }
  221.            value2-=4; /* continue drawing line */
  222. }    /*   value2<4 and move flag set type fprintf(%d %d l)*/
  223. if(value2<2&&moveflag==1){
  224.     fprintf(PPtr,"%d %d l\nS\n",column7,rownumber);
  225.     moveflag=0;
  226. }
  227. if(value2>=2){
  228.     if(moveflag==0){
  229.         fprintf(PPtr,"%d %d m\n",column7,rownumber); 
  230.                 moveflag=1;
  231.     }
  232.             value2-=2;
  233. }
  234. if(value2<1&&moveflag==1){    
  235.     fprintf(PPtr,"%d %d l\nS\n",column8,rownumber);
  236.     moveflag=0;
  237.     }
  238. if(value2==1){
  239.     if(moveflag==0){
  240.         fprintf(PPtr,"%d %d m\n",column8,rownumber); 
  241.   fprintf(PPtr,"%d %d l\nS\n",column9,rownumber);
  242. }else{
  243.   fprintf(PPtr,"%d %d l\nS\n",column9,rownumber);
  244. }
  245. }
  246. }
  247.